package regression.model;

import java.util.List;

import loss.LossFun;
import regularizer.Regularizer;
import solver.Searcher;

/**
 * Abstract class for regression
 * @author tigerzhong
 *
 */
public abstract class AbstractRegression {
    /**
     * Loss function
     */
    protected LossFun losser;
    /**
     * Regularization term
     */
    protected Regularizer regularizer;
    /**
     * Solve method, gradient descent etc.
     */
    protected Searcher searcher;
    /*Getter and Setter*/
    public LossFun getLosser() {
        return losser;
    }
    public void setLosser(LossFun losser) {
        this.losser = losser;
    }
    public Regularizer getRegularizer() {
        return regularizer;
    }
    public void setRegularizer(Regularizer regularizer) {
        this.regularizer = regularizer;
    }
    public Searcher getSearcher() {
        return searcher;
    }
    public void setSearcher(Searcher searcher) {
        this.searcher = searcher;
    }
    /**
     * Set parameters
     * @param paremeters
     */
    public abstract void setParameters(double[][] parameters);
    /**
     * Update the parameters with gradient
     * @param idx
     * @param devList
     * @return updated gradient
     */
    public abstract double[] update(int idx, List<double []> devList);
    /**
     * Predict the target of one instance
     * @param instance
     * @return target values
     */
    public abstract double[] predict(double[] instance);
    /**
     * Initialize
     * @param confFile
     */
    public abstract void init(String confFile);
    /**
     * Get the gradient, given target/instance/parameter
     * @param instance
     * @param target
     * @return sub-gradient
     */
    public abstract double[][] getGradient(double[] instance, double[] target);
    /**
     * Get loss, given target/instance/parameter
     * @param instance
     * @param target
     * @return loss values
     */
    public abstract double[] getLoss(double[] instance, double[] target);
}
